package Lee_code;

import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

public class Lee_841_bfs {

    public boolean canVisitAllRooms(List<List<Integer>> rooms) {

        int sum_room = rooms.size();
        HashSet<Integer> entered = new HashSet<>();
        Deque<Integer> deque = new LinkedList();
        deque.offer(0);
        while(!deque.isEmpty())
        {
            int cur = deque.poll();
            List<Integer> cur_open = rooms.get(cur);
            for(int i: cur_open)
            {
                if(!entered.contains(i))
                {
                    deque.offer(i);
                }
            }
            entered.add(cur);
        }
        return entered.size()==sum_room;
    }
}
